/* SPDX-License-Identifier: GPL-2.0 */
/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2023-2023. All rights reserved.
 * Author: Huawei OS Kernel Lab
 * Create: Thu Aug 15 16:14:23 2023
 */

#ifndef __LIBLINUX_KERNFS_H__
#define __LIBLINUX_KERNFS_H__

#ifdef CONFIG_LIBLINUX

#include <linux/kernfs.h>
#include <linux/sysctl.h>

struct liblinux_kernfs_ops {
	struct kernfs_syscall_ops kops;
	int (*create_dir)(const char *name, unsigned int mode);
	int (*create_file)(const char *name, unsigned int mode,
			   struct liblinux_pal_kernfs_ops *fops,
			   void *ctx);
	int (*create_symlink)(const char *name, unsigned int mode,
			      const char *linkdata);
	int (*unlink)(const char *name);
	int (*notify)(const void *ctx, const char *name);
};
int liblinux_sysfs_init(void);

struct proc_dir_entry;
void (struct proc_dir_entry *dp);
void liblinux_procfs_unlink(struct proc_dir_entry *dp);

ssize_t vfs_read_full(struct file *filep, char __user *buf, size_t size, loff_t *pos);
ssize_t vfs_write_full(struct file *filep, const char __user *buf, size_t size, loff_t *pos);

struct file *transfs_fget(unsigned int fd);
void transfs_fput(struct file *file);

/* proc_sysctl */
int liblinux_procfs_sys_register(const char *dir, struct ctl_table_header *head,
				 struct ctl_table *table);

#endif /* CONFIG_LIBLINUX */
#endif /* __LIBLINUX_KERNFS_H__ */
